home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / sdate.exe / DATE.CPP < prev    next >
C/C++ Source or Header  |  1992-06-18  |  2KB  |  70 lines

  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <iostream.h>
  4. #include "pxengine.h"
  5.  
  6. #define TABLENAME        "datesort"
  7. #define PXErr(param) PXError(__FILE__, __LINE__, param)
  8.  
  9. int PXError (char*, int, int);
  10. int GlobalPXErr;
  11. unsigned _stklen = 30000;
  12.  
  13. int main(void)
  14. {
  15.     TABLEHANDLE tblHandle;
  16.     RECORDHANDLE recHandle;
  17.     FIELDHANDLE fldHandles[] = {2};
  18.     RECORDNUMBER r;
  19.     int pxErr,day,month,year;
  20.     int i;             //watch i in TD to see return values
  21.     DATE date;
  22.  
  23.     PXErr(PXInit());
  24.     PXErr(PXKeyAdd(TABLENAME,1,fldHandles,PRIMARY)); //p-index set on NAME
  25.     PXErr(PXKeyAdd(TABLENAME,1,fldHandles,INCSECONDARY));//s-index on B-DAY
  26. //    PXErr(PXTblOpen(TABLENAME, &tblHandle, 0, 0)); //open table on primary
  27.     PXErr(PXTblOpen(TABLENAME, &tblHandle, 2, 0)); //open on secondary
  28.  
  29.     PXErr(PXRecBufOpen(tblHandle, &recHandle));
  30.     PXErr(PXRecFirst(tblHandle));      //move cursor to top of table
  31.  
  32.     for (int j = 1; j < 5; j++)        //table has 5 records
  33.     {
  34.       PXErr(PXRecGet(tblHandle,recHandle)); //load record buffer
  35.       PXErr(PXGetDate(recHandle,2,&date));  //get date from buffer
  36.       PXErr(PXDateDecode(date,&month,&day,&year));
  37.       cout<<"Date in record #"<<j<<" is  "<<month<<" "<< day<<" "<< year<<endl;
  38.       if ( j != 4 ) PXErr(PXRecNext(tblHandle));         //move down 1 record
  39.     }
  40.  
  41.     PXErr(PXDateEncode(2,3,66,&date));
  42.     PXErr(PXPutDate(recHandle,2,date));     //load record buffer w/date
  43.     PXErr(PXSrchFld(tblHandle,recHandle,2,CLOSESTRECORD));  //search
  44.     PXErr(PXRecNum(tblHandle,&r));                          //get rec number
  45.     PXErr(PXRecGet(tblHandle,recHandle));    //load record buffer
  46.     PXErr(PXGetDate(recHandle,2,&date));     //get date from buffer
  47.     PXErr(PXDateDecode(date,&month,&day,&year));
  48.     cout<<"Closest value to 2 3 66 is located in "
  49.         <<"record #"<<r <<": "<<month<<" "<< day<<" "<< year<<endl;
  50.  
  51.  
  52.     PXErr(PXTblClose(tblHandle));
  53.     PXErr(PXKeyDrop(TABLENAME,0));
  54.     PXErr(PXExit());
  55.     return 0;
  56. }
  57.  
  58. int PXError(char* module, int line, int retval)
  59. {
  60.     if (retval == PXSUCCESS)
  61.     {
  62.         GlobalPXErr = PXSUCCESS;
  63.         return retval;
  64.     }
  65.     cout<<"module: "<<module<<"    line: "<<line<<"    error#: "<<retval<<endl;
  66.     cout<<"\""<<PXErrMsg(retval)<<"\""<<endl;
  67.     GlobalPXErr = retval;
  68.     return retval;
  69. }
  70.